<template>
	<!-- 个人中心   密码修改 -->
	<div class="p-password">
		<div class="zmlTitle">{{$t('common.leftNav.passwordMod')}}</div>
		<div class="company-password-table">
			<table>
				<tr>
					<td class="h66">{{$t('common.company.password')}}：</td>
					<td><el-input v-model="oldPwd"></el-input></td>
					<td></td>
				</tr>
				<tr>
					<td class="h66">{{$t('common.company.newPassword')}}：</td>
					<td><el-input v-model="newPwd"></el-input></td>
					<td class="font12 h99">{{$t('common.company.companytask6')}}</td>
				</tr>
				<tr>
					<td class="h66">{{$t('common.company.confirmPassword')}}：</td>
					<td><el-input v-model="newPwd2"></el-input></td>
					<td class="font12 h99">{{$t('common.company.companytask6')}}</td>
				</tr>
				<tr>
					<td></td>
					<td><button class="zmlBtn1 comfirmBtn" @click="bindComfirm">{{$t('common.company.confirmModification')}}</button></td>
					<td></td>
				</tr>
			</table>
		</div>
	</div>
	
</template>
<script>
	import { ajax, showToast, ajaxAdd, notBlankStr } from '@/utils/js.js';
	import { updatePwd } from '@/services/api.js';
	const log = console.log;
	
  export default{
    data(){
      return{
		oldPwd:'',
		newPwd:'',
		newPwd2:'',
      }
    },
	methods:{
		canSubmit() {
			if (notBlankStr(this.oldPwd) == false) {
				showToast(this, this.$t('common.modifyPwd.inputOrigin'));
				return false
			}
			if (notBlankStr(this.newPwd) == false) {
				showToast(this, this.$t('common.modifyPwd.inputNew'));
				return false
			}
			if (this.newPwd.length < 6 || this.newPwd.length > 16) {
				showToast(this, this.$t('common.modifyPwd.newFormat'));
				return false
			}
			if (notBlankStr(this.newPwd2) == false) {
				showToast(this, this.$t('common.modifyPwd.inputConfirm'));
				return false
			}
			if (this.newPwd2.length < 6 || this.newPwd2.length > 16) {
				showToast(this, this.$t('common.modifyPwd.confirmFormat'));
				return false
			}
			if (this.newPwd != this.newPwd2) {
				showToast(this, this.$t('common.modifyPwd.differ'));
				return false
			}
			return true
		},
		
		// 确认修改
		bindComfirm(){
			if (this.canSubmit()) {
				this.modifyPwdReq()
			}
		},
		
		modifyPwdReq() {
			let data = {
				"code": "",
				"newPwd": this.newPwd,
				"oldPwd": this.oldPwd,
				"phone": ""
			}
			log(data)
			ajaxAdd(this, updatePwd, data, res => {
				log(res)
				this.$message({ message: '修改成功', type: 'success' });
			});
		},
	}
  }
</script>
<style lang="scss">
.p-password{
	background-color: #fff;
	min-height: 890px;
	padding: 0 30px;
	.company-password-table{
		padding-left: 13px;
		table{
			td{
				padding: 6px 0;
			}
			input{
				width: 300px;
				margin-right: 14px;
			}
			button{
				width: 300px;
				height: 34px;
				background:rgba(15,84,188,1);
				color: #fff;
				margin-top: 24px;
			}
		}
	}
	
}
</style>
